package com.bbx.demo.socket;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.Charset;

@Slf4j
//@ChannelHandler.Sharable
public class SocketServerHandler  extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        String s = (String) msg;
        log.info("接受到客户端的消息[{}]", s);
        String res = "我是服务端响应的消息";
        ctx.writeAndFlush(Unpooled.copiedBuffer(res.getBytes(Charset.forName("utf-8"))));
    }
}
